<?php
/**
 * Description of addSoftwareCopyright
 *
 * @author Runner
 */

class addSoftwareCopyrightInfo extends AddInformation{
    private $softwareCopyright;
    private $queryStr;
    
    function __construct($softwareCopyright=null) {
        $this->softwareCopyright = $softwareCopyright;
        $this->queryStr = sprintf('insert into SoftwareCopyright(name, responsible, submitDate, authorizeDate, '
                                        . 'state, auditingState)'.
                                        'values("%s", "%s", "%s", "%s", "%s", "%s")', 
                                        $this->softwareCopyright->name, $this->softwareCopyright->responsible,
                                        $this->softwareCopyright->submitDate, $this->softwareCopyright->authorizeDate,
                                        $this->softwareCopyright->state, $this->softwareCopyright->auditingState
                                    );
        
    }
    
    public function add($linkIdentify) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->softwareCopyright==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$softwareCopyright as $value) {
            if($this->softwareCopyright->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        $timePattern = '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/';       // 日期的正则表达式模式
        if( preg_match($timePattern, $this->softwareCopyright->submitDate)==0 ){        // 提交日期
            return false;
        }
        if( preg_match($timePattern, $this->softwareCopyright->authorizeDate)==0 ){     // 授权日期
            return false;
        }
        /* 比较日期 */
        if( strtotime($this->softwareCopyright->submitDate)>strtotime($this->softwareCopyright->authorizeDate) ){
            return false;
        }
        return true;
    }
}
